#include <iostream>
#include <vector>
using namespace std;

int n,k;
vector<int> mount;

int main(){
    cin >> n >> k;
    mount.resize(n+1);
    vector<int> dp(n+1, 0x3f3f3f3f);
    dp[1] = 0;
    for(int i=1;i<=n;i++) cin >> mount[i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k && i+j <= n;j++){
            int spend = (mount[i+j] > mount[i]) ? mount[i+j] - mount[i] : 0;
            dp[i+j] = min(dp[i+j], dp[i] + spend);
        }
    }
    cout << dp[n] << endl;
    return 0;
}